package com.goldcn.cart.controller;

import com.goldcn.cart.dto.GoodsCartDto;
import com.goldcn.cart.dto.UpdateGoodsCartDto;
import com.goldcn.cart.service.GoodsCartService;
import com.goldcn.cart.vo.GoodsCartVo;
import com.goldcn.interceptor.SystemContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by Administrator on 2016/11/15.
 */
@RestController
@RequestMapping("/cart")
@Api(value = "购物车", description = "购物车服务")
public class GoodsCartController {
    @Autowired
    private GoodsCartService goodsCartService;

    @ApiOperation(value = "添加商品至我的购物车")
    @RequestMapping(method = RequestMethod.POST)
    public Object addMyShoppingCart(@RequestBody GoodsCartVo goodsCartVo) {
        return goodsCartService.addMyShoppingCart(goodsCartVo, SystemContext.getCompanyID());
    }

    @ApiOperation(value = "添加商品至我的购物车v2")
    @RequestMapping(value = "/v2", method = RequestMethod.POST)
    public Object addMyShoppingCartv2(@RequestBody GoodsCartVo goodsCartVo) {
        return goodsCartService.addMyShoppingCart(goodsCartVo, SystemContext.getCompanyID());
    }

    @ApiOperation(value = "从购物车移除我的商品(批量)")
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public Object removeMyShoppingCart(@RequestBody List<Long> cartIDs) {
        return goodsCartService.removeMyShoppingCart(cartIDs);
    }

    @ApiOperation(value = "清空购物车")
    @RequestMapping(value = "/clear/{userID}", method = RequestMethod.DELETE)
    public Object clearMyShoppingCart(@PathVariable Long userID) {
        return goodsCartService.clearMyShoppingCart(userID);
    }

    @ApiOperation(value = "查询我的购物车")
    @RequestMapping(value = "/{userID}/{pageSize}/{pageNum}", method = RequestMethod.GET)
    public Object queryMyShoppingCart(@PathVariable Long userID, @PathVariable Integer pageNum, @PathVariable Integer pageSize) {
        return goodsCartService.queryMyShoppingCart(null, userID, pageNum, pageSize);
    }

    @ApiOperation(value = "店铺版本2018：查询我的购物车")
    @RequestMapping(value = "shop/{shopID}/{userID}/{pageSize}/{pageNum}", method = RequestMethod.GET)
    public Object queryMyShoppingCartByShop(@PathVariable Long shopID, @PathVariable Long userID, @PathVariable Integer pageNum, @PathVariable Integer pageSize) {
        return goodsCartService.queryMyShoppingCart(shopID, userID, pageNum, pageSize);
    }

    @ApiOperation(value = "修改我的购物车商品信息")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Object updateGoodsCartInfo(@RequestBody List<UpdateGoodsCartDto> record) {
        return goodsCartService.updateGoodsCartInfo(record);
    }


    @ApiOperation(value = "优惠券使用时购物车按分类进行金额统计")
    @RequestMapping(value = "/couponByClazz", method = RequestMethod.POST)
    public Object getCartsByClassify(@RequestBody List<Long> cardIDs) {
        return goodsCartService.selectListByCartIds(cardIDs);
    }


}
